<!--
 * @Author: Mcc
 * @Date: 2024-08-21 18:14:12
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-10-21 11:53:23
 * @FilePath: \ft-apply-admin\src\views\applicationDetails\Modals\BookTrainModal.vue
 * @Description: 
 * 
 * Copyright (c) 2024 by Mcc, All Rights Reserved. 
-->
<template>
  <BasicModal :show="show" title="预约培训" width="30%" :widthComfirm="true" @comfirm="comfirm">
    <template #content>
      <CommonForm :formList="formList" ref="formRef"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import BasicModal from "./BasicModal.vue";

import { ref, watch } from "vue"
import type { IndexFormItem } from "@/views/ApplicationDetails/application-type.ts";
import { trainingSchedule, selectTrainingNumberList } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
import { message } from "ant-design-vue";
const store = comStores()
const { userName } = store.userInFor
const show = ref<boolean>(false)
// ,displayRender:true
const formList = ref<IndexFormItem[]>([
  {
    label: "培训期数", name: "trainingId", value: "", component: 'cascader', options: [
    ]
  },
  {
    label: "口味选择", name: "taste", value: "", component: 'select', required: false, options: [
      {
        label: "清真",
        value: "清真"
      }
      , {
        label: "非清真",
        value: "非清真"
      }
    ]
  },
  { label: "忌口食物", name: "notEat", value: "", disabled: true, component: 'textarea', required: false },
  { label: "备注", name: "remark", value: "", required: false, disabled: true, component: 'textarea' },
  { label: "发送邮件通知", name: "isSend", value: true, component: 'isSend', required: false },
])
const formRef = ref<any>(null)

const comfirm = async () => {
  const res = await formRef.value.submitForm();
  const { resumeId, processId, processSort } = store.currentResume;
  console.log(res, 'res');
  const param: any = {
    resumeId: resumeId,
    processId: processId,
    result: "通过",
    operator: userName
  }
  // param.remark = res[1].value
  // param.isSend = res[2].value
  res.forEach(el => {
    param[el.name] = el.value
  })
  param.trainingId = res[0].value[2]
  const data = await trainingSchedule(param)
  if (data && data.code === '10000') {
    message.success("操作成功")
    await store.getResumeInfo(resumeId);
    show.value = false
  } else {
    message.error(data.msg)
  }
}
watch(() => show.value, async (val) => {
  if (val) {
    const data = await selectTrainingNumberList();
    console.log(data, '===>daat')
    if (data && data.code === '10000') {
      data.data.forEach(l1 => {
        l1.label = l1.dateTime
        l1.value = l1.dateTime
        l1.children = l1.monthList
        l1.monthList.forEach(l2 => {
          l2.label = l2.dateTime
          l2.value = l2.dateTime
          l2.children = l2.numberList
          l2.numberList.forEach(l3 => {
            l3.label = l3.startTimeEndTime + (l3.isOnline == 0 ? ' (未上线)' : "")
            l3.value = l3.trainingNumberId
          })
        })
      })
      formList.value[0].options = data.data
    }
  }
})
defineExpose({ show })
</script>

<style lang="less" scoped></style>
